<script setup lang="ts">
import { ref } from "vue";

import * as ocr from '@paddlejs-models/ocr';

defineProps<{ msg: string }>();

const count = ref(0);
async function getText(e: any) {
  const file = e?.target?.files?.[0];
  console.log(`------file------`,file)
  if (!file) {
    return;
  }
  await ocr.init();
  const imageSrc = URL.createObjectURL(file);
  const image = new Image();
  console.log(`------imageSrc------`,imageSrc)
  image.src = imageSrc;
  image.onload = async () => {
    const res = await ocr.recognize(image);
    console.log(`------res------`,res)
  };
}
/* reader.onload = async function (event) {
    const imgData = event.target!.result;
    const res = await ocr.recognize(imgData);
   const textArr = res.map((item:any) => item.text);
   console.log(`-------textArr-----`,textArr)
    
  };
Tesseract.recognize(
      imgData,
      'chi_sim', // 识别语言（这里以英文为例）
      { logger: m => console.log(m) } // 可选的日志函数，用于查看处理进度
    ).then(({ data: { text } }) => {
      console.log(`------text------`,text)
    }); */
</script>

<template>
  <h1>{{ msg }}</h1>

  <div class="card">
    <input type="file" @change="getText">count is {{ count }}</input>
    <p>
      Edit
      <code>components/HelloWorld.vue</code> to test HMR
    </p>
  </div>

  <p>
    Check out
    <a href="https://vuejs.org/guide/quick-start.html#local" target="_blank">create-vue</a>, the official Vue + Vite
    starter
  </p>
  <p>
    Learn more about IDE Support for Vue in the
    <a href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support" target="_blank">Vue Docs Scaling up Guide</a>.
  </p>
  <p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
</template>

<style scoped>
.read-the-docs {
  color: #888;
}
</style>
